<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    function foo(fn) {
      // 通过fn去调用bar函数的过程,称为"函数的回调"
      fn()
    }
    function bar() {
      console.log("bar函数被执行了~")
    }
    foo(bar)


    function request(url, callback) {
      console.log("根据URL向服务器发送网络请求")
      console.log("需要花费较长的时间")
      var list = ["JavaScript", "JavaScript学习"]
      callback(list)
    }

    // 匿名函数
    request("url", function (res) {
      console.log("在handleResult中拿到结果:", res)
    })
  </script>
</body>

</html>